﻿using System.IO;
namespace org.webguvenligi.NSecureImageLib.GraphicFileFormats.JPEG
{
    /// <summary>
    /// 
    /// </summary>
    public class JpegParser : BaseImageParser
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegParser"/> class.
        /// </summary>
        /// <param name="bitmapStream"></param>
        /// <remarks>
        /// Magic Number Check Is Already Done Here, So Extending Classes Should Expect The BinaryStream
        /// After The Header Check Completed.
        /// </remarks>
        public JpegParser(Stream bitmapStream)
            : base(bitmapStream)
        {
        }

        protected override bool ParseImage()
        {
            using (BinaryReader pngReader =
                   new BinaryReader(ImageStream))
            {
                JPEGBaseChunk.GetChunks(pngReader);
            }
            return true;
        }

        static byte[] JPEGHeader =
            new byte[] { 0xff, 0xd8 };

        protected override string FormatExceptionMessage
        {
            get { return "Not A Valid JPG File"; }
        }

        protected override byte[] HeaderSignature
        {
            get { return JPEGHeader; }
        }

        public override void WriteImage(Stream targetStream, bool removeMetadataTags)
        {

            //throw new System.NotImplementedException();
        }
    }
}